package com.jia.together.controller;


import com.jia.together.entity.Resource;
import com.jia.together.service.ResourceService;
import com.jia.together.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dujiajia
 * @since 2021-02-19
 */
@RestController
@RequestMapping("/resource")
public class ResourceController {

    @Autowired
    private ResourceService resourceService;

    @GetMapping("/list")
    public R list(@RequestParam Long pageNum,@RequestParam Long pageSize) {
        Map<String,Object> map = resourceService.selectPageList(pageNum,pageSize);
        return R.ok().data(map);
    }
    @GetMapping("/info/{id}")
    public R info(@PathVariable String id){
        Resource byId = resourceService.getById(id);
        return R.ok().data("data",byId);
    }
    @PostMapping("/add")
    public R add(@RequestBody Resource resource){
        resourceService.save(resource);
        return R.ok();
    }
    @PutMapping("/update")
    public R update(@RequestBody Resource resource){
        resourceService.updateById(resource);
        return R.ok();
    }
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable String id){
        resourceService.removeById(id);
        return R.ok();
    }
}

